<?php
namespace Admin\Model;
use Think\Model;

class UsersModel extends Model {
    private $id = null;
    function __construct($id = null){
        parent::__construct();
        $this->id = $id;
    }

    function getInfo($id = null, $fields = null){
        $this->id = empty($id) ? false : intval($id);

        $m = $this->where(array('user_id'=>$this->id));
        if (empty($this->id)) {
            return false;
        }

        if (!empty($fields) && is_string($fields)) {
            $m = $m->field($fields);
        }

        $res = $m->find();

        return $res;
    }

    function getByName($name){
        if (empty($name)) {
            return false;
        }

        return $this->where(array('user_name'=>trim($name)))->find();
    }

    function getById($id){
        if (empty($id)) {
            return false;
        }

        return $this->where(array('user_id'=>intval($id)))->find();
    }

    function updInfo($id, $data){

        if (empty($id) || empty($data)) {
            return false;
        }

        $res = $this->where("user_id='$id'")->data($data)->save();

        if ($res !== fasle) {
            addlog('编辑会员信息，会员UID：' . $id);
        }

        // $res = $this->where("user_id='$id'")->save($data);
        return $res !== false;
    }


    function freezeUser($id){
        if (empty($id)) {
            return false;
        }

        $res = $this->where(array('user_id'=>$id))->data(array('status'=>-1))->save();

        return $res !== false;
    }
}

